package components.plugins.effects
{
	import UIUtils.uif_util;
	
	import com.unitzeroone.fx.ImageDithering;
	import com.unitzeroone.fx.ImageDitheringType;
	
	import flash.display.BitmapData;

	public class clte_dithering extends clt_baseEffect 	{
		private static const types: Array = [
			ImageDitheringType.NO_DITHER, ImageDitheringType.FALSE_FLOYD_STEINBERG, ImageDitheringType.FLOYD_STEINBERG, ImageDitheringType.STUCKI
		]
			
		public static var MAXLEVELS: int = 10;
		
		public function clte_dithering(a_params:Object) {
			super(uif_util.unionObj({
				typeIndex	: 0, 
				levels		: 1,
				gray		: true
			}, a_params));
		}
		
		override public function execute(bitmapData: BitmapData):void {
			ImageDithering.dither(bitmapData, types[params.typeIndex], params.levels, params.gray);
		}
		
		override public function incValue1(): void {
			params.typeIndex = (params.typeIndex + 1) % types.length;
		}		

		override public function incValue2(): void {
			params.gray = !params.gray;
		}

		override public function incValue3(): void {
			params.levels = changeValue(params.levels, 1, MAXLEVELS);
		}
		
		override protected function getParamName():Array {
			return [
				locale.TYPE,
				locale.GRAY,
				locale.LEVELS
			];
		}
		
		override protected function getValues():Array {
			return [
				params.typeIndex/types.length * 100,
				params.gray?100:0,
				params.levels/MAXLEVELS * 100
			];
		}
		
		override protected function setValues(a_set:Array):void {
			params.typeIndex  	= a_set[0] * .01;
			params.gray  		= a_set[1]>50?true:false;
			params.levels  		= Math.ceil(a_set[2]/100 * MAXLEVELS);
			super.setValues(a_set);
		}		
	}
}